package it.koutifaris.travianmap.view.mainview;

import static it.koutifaris.travianmap.communication.mapdownloader.DownloadProgressHelper.downloadServiceHelper;
import it.koutifaris.travianmap.R;
import it.koutifaris.travianmap.command.Command;
import it.koutifaris.travianmap.context.HasApplicationContex;
import it.koutifaris.travianmap.dal.TravianServerService.TravianServer;
import it.koutifaris.travianmap.ui.MapActivity;
import android.widget.Toast;

class OpenServerMapCommand extends HasApplicationContex implements Command {

	private final TravianServer travianServer;

	public OpenServerMapCommand(TravianServer travianServer) {
		this.travianServer = travianServer;
	}

	@Override
	public void execute() {
		if (!isMapInDownload()) {
			MapActivity.startActivity(getActivity(), travianServer);
		} else {
			Toast.makeText(getActivity(), R.string.maplist_open_while_donwloading_error, Toast.LENGTH_SHORT).show();
		}
	}

	private boolean isMapInDownload() {
		return downloadServiceHelper().isDownloadInProgress(travianServer.getServerId());
	}
}
